<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="css/eui.css">
</head>
<body>
<h1>登录页面</h1>
<form action="">
    <input type="text" name="account" v-model="userInfo.contactInfo" placeholder="请输入电话号码或邮箱地址"><br>
    <input type="password" name="password" v-model="userInfo.password" placeholder="请输入密码"><br>
    <input type="checkbox" name="remember" v-model="userInfo.remember">记住账号和密码<br>
    <input type="button" value="登录" @click="login()">
    <input type="button" value="注册" @click="reg()">
</form>
<script src="js/vue.min.js"></script>
<script src="js/eui.js"></script>
<script src="js/axios.min.js"></script>
<script>
    let v = new Vue({
        el: "form",
        data: {
            userInfo: {
                //account:{phoneNumber:"",emailAddress:""},
                contactInfo: "",
                password: "",
                remember: ""
            }
        },
        methods: {
            login() {
                axios.post("/login", v.userInfo).then(function (response) {
                    if (response.data.state == 200) {
                        alert("登录成功！");
                        //location.href="/";
                        location.href = "user/info.html";
                    } else if (response.data.state == 404) {
                        alert("账号不存在，请先注册！");
                    } else {
                        alert("密码错误！");
                    }
                })
            },
            reg() {
                location.href = "/register.html";
            }

        }
    })
    //获取cookie里面的数据
    let cookieStr = document.cookie;
    //'account={phoneNumber=12345678901, emailAddress=xxxx@xx.com}; password=123456'
    let cookieArr = cookieStr.split(";");
    for (let cookie of cookieArr) {
        let arr = cookie.split("=")
        let name = arr[0].trim();  // trim()去掉空格
        let value = arr[1];
        if (name == "emailAddress") {
            v.userInfo.emailAddress = value;
        } else if (name == "password") {
            v.userInfo.password = value;
        }
    }

</script>
</body>
</html>